//
//  ZuzhiDetail.m
//  ZhuoxinAgriculture
//
//  Created by 左忠飞 on 16/11/8.
//  Copyright © 2016年 KKING. All rights reserved.
//

#import "ZuzhiDetail.h"
#import "ZuzhiDetailCell.h"

#define kSSize [UIScreen mainScreen].bounds.size

@interface ZuzhiDetail () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSArray <NSArray *> *datas;
@property (nonatomic, strong) UITableView *tbView;
@property (nonatomic, strong) NSArray<NSArray *> *datanum;
@property (nonatomic, strong) NSArray<NSArray *> *datasNongmin;

@end

@implementation ZuzhiDetail

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"详细信息";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSSize.width, kSSize.height) style:UITableViewStyleGrouped];
    self.tbView.dataSource = self;
    self.tbView.delegate = self;
    self.tbView.rowHeight = 45;
    self.tbView.tableFooterView = [UIView new];
    [self.view addSubview:self.tbView];
    //    self.view.backgroundColor = [UIColor colorWithRed:237.0/255.0 green:237.0/255.0 blue:237.0/255.0 alpha:1.0];
    self.tbView.backgroundColor = [UIColor colorWithRed:237.0/255.0 green:237.0/255.0 blue:237.0/255.0 alpha:1.0];
    self.tbView.scrollEnabled = NO;
    
    if ([self.number isEqualToString:@"农场"]) {
        [self.view addSubview:self.tbView];
    }
    else if ([self.number isEqualToString:@"4"]){
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kSSize.width, kSSize.height)];
        imgView.image = [UIImage imageNamed:@"123"];
        [self.view addSubview:imgView];
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 20, 70, 40)];
        [self.view addSubview:btn];
        [btn addTarget:self action:@selector(btnPop) forControlEvents:UIControlEventTouchUpInside];
        self.navigationController.navigationBarHidden = YES;
    }
    
}

- (void)btnPop{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidDisappear:(BOOL)animated {
    self.navigationController.navigationBarHidden = NO;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([self.number isEqualToString:@"农场"]) {
        return 2;
    }
    else if([self.number isEqualToString:@"大户"]){
        return 1;
    }
    else if([self.number isEqualToString:@"小农"]){
        return 1;
    }
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([self.number isEqualToString:@"农场"]) {
        if (section == 0) {
            return 3;
        } else {
            return 2;
        }
    }
    else if ([self.number isEqualToString:@"大户"]) {
        return 6;
    }
    else if ([self.number isEqualToString:@"小农"]) {
        return 9;
    }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZuzhiDetailCell *cell = [ZuzhiDetailCell cellWithTableView:tableView];
    
    if ([self.number isEqualToString:@"农场"]) {
        if (indexPath.section == 0) {
            NSArray *descArr = self.datanum[indexPath.section];
            NSArray *desc = descArr[0];
            NSArray *answer = descArr[1];
            cell.desc.text = desc[indexPath.row];
            cell.answer.text = answer[indexPath.row];
        } else {
            NSArray *descArr = self.datanum[indexPath.section];
            NSArray *desc = descArr[0];
            NSArray *answer = descArr[1];
            cell.desc.text = desc[indexPath.row];
            cell.answer.text = answer[indexPath.row];
        }
    }
    else if ([self.number isEqualToString:@"大户"]) {
        NSArray *desc = self.datas[0];
        NSArray *answer = self.datas[1];
        cell.desc.text = desc[indexPath.row];
        cell.answer.text = answer[indexPath.row];
    }
    
    else if ([self.number isEqualToString:@"小农"]) {
        NSArray *desc = self.datasNongmin[0];
        NSArray *answer = self.datasNongmin[1];
        cell.desc.text = desc[indexPath.row];
        cell.answer.text = answer[indexPath.row];
    }
    return cell;
}

- (NSArray<NSArray *> *)datanum {
    if (!_datanum) {
        _datanum = @[
                     @[
                         @[@"农场名称",
                           @"所在地区" ,
                           @"组织机构代码" ,
                           ],
                         @[@"农兴农场",
                           @"黑龙江省大庆市大同区",
                           @"12345678901",
                           ]
                         ],
                     @[
                         @[@"姓名",
                           @"手机号码"
                           ],
                         @[@"张三",
                           @"18684849565"
                           ]
                         ],
                     ];
    }
    return _datanum;
}


- (NSArray<NSArray *> *)datas {
    if (!_datas) {
        _datas = @[@[
                       @"姓名",
                       @"社员编号",
                       @"身份证号码",
                       @"手机号码",
                       @"所在地区",
                       @"身份"
                       ],
                   @[
                       @"张三",
                       @"123456",
                       @"12345678901",
                       @"12345678901",
                       @"黑龙江省 哈尔滨市 伊春",
                       @"大户"
                       ]
                   
                   ];
    }
    return _datas;
}

//小农
- (NSArray<NSArray *> *)datasNongmin {
    if (!_datasNongmin) {
        _datasNongmin = @[@[
                              @"姓名",
                              @"社员编号",
                              @"身份证号码",
                              @"手机号码",
                              @"所在地区",
                              @"身份",
                              @"隶属合作社",
                              @"承包土地面积",
                              @"实际土地面积",
                              ],
                          @[
                              @"张三",
                              @"123456",
                              @"12345678901",
                              @"12345678901",
                              @"黑龙江省 哈尔滨市 伊春",
                              @"小农",
                              @"罗庄合作社",
                              @"100(公顷)",
                              @"200(公顷)"
                              ]
                          
                          ];
    }
    return _datasNongmin;
}



@end
